import {
  wxRequest
} from '../../utils/server.js';
const _wxRequest = new wxRequest();
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    cId: '',
    show: false,
    authCode: ''
  },

  onLoad: function (option) {
    if (option.typeId) {
      this.data.typeId = option.typeId
    }
    //this.initDyeRecord()
  },

  authCodeAndGetDyeRecord() {
    if (this.data.authCode != "888888") {
      wx.showToast({
        icon: 'error',
        title: '操作码错误',
      })
      return;
    }
    this.getDyeRecord();
  },

  inputHandler(e) {
    const inputValue = e.detail.value;
    this.setData({
      authCode: inputValue
    })
  },

  onUnload: function () {
    // this.cancelRecord()
  },

  startRecord() {
    this.setData({
      show: true
    })
  },

  getDyeRecord() {
    var params = {
      recType: 3,
      devId: this.data.typeId
    }
    _wxRequest.wxTonkenAjax({
      url: app.globalData.apiUrl + '/gds/protected/dyeRecord/create',
      method: 'POST',
      data: params,
    }, (res) => {
      this.setData({
        cId: res.vo.id
      }, () => {
        wx.showToast({
          title: '校准成功',
        })
      })
    })
  },

  //退出校准
  cancelRecord: function () {

    _wxRequest.wxTonkenAjax({
      url: app.globalData.apiUrl + '/gds/protected/dyeRecord/cancelRecord?id=' + this.data.cId,
      method: 'GET',
      data: {},
    }, (res) => {
      wx.navigateBack({})
    })

  },

  cencelHanld: function () {
    wx.navigateBack({})
  }




})